package com.dnjn.happiness.emo.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dnjn.happiness.emo.domain.vo.AvgScoreChangeBean;
import com.dnjn.happiness.emo.api.domain.EmoAvgScoreDaily;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 快乐值日均Mapper接口
 *
 * @author happiness
 * @date 2024-02-27
 */
public interface EmoAvgScoreDailyMapper extends BaseMapper<EmoAvgScoreDaily> {

    @Select("SELECT ROUND(AVG(score_avg),0) FROM emo_avg_score_daily WHERE user_id = #{userId} AND YEARWEEK(DATE_FORMAT(curr_date,'%y-%m-%d'),1) = #{weekOfYear} ")
    BigDecimal getCurrWeekHappinessScore(@Param("userId") Long userId, @Param("weekOfYear") String weekOfYear);

    @Select(" SELECT e.id, u.user_id, u.nick_name, u.empno, e.curr_date, e.score_avg, e.score_changed FROM emo_avg_score_daily e LEFT JOIN sys_user u USING(user_id) WHERE e.user_id = #{userId} AND DATEDIFF(e.curr_date,NOW()) = -1 ")
    EmoAvgScoreDaily selectDailyScoreAvgByUserId(Long userId);

    @Select(" SELECT score_avg AS score,curr_date AS date FROM emo_avg_score_daily WHERE curr_date BETWEEN #{startTime} AND #{endTime} AND user_id = #{userId} AND deleted = '0' ORDER BY curr_date ")
    List<AvgScoreChangeBean> getScoreChangeByUserId(@Param("userId") Long userId, @Param("startTime") LocalDate startTime, @Param("endTime") LocalDate endTime);

}
